package com.tsingteng.cosfun.ui.search;


import android.util.Log;

import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.FollowBean;
import com.tsingteng.cosfun.bean.SearchResp;
import com.tsingteng.cosfun.bean.SearchUserResp;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SearchPresenter extends BasePresenter<SearchContact.ISearchView> implements SearchContact.ISearchPresenter{
    SearchModel searchModel;
    SearchContact.ISearchView iSearchView;
    public SearchPresenter(){
        this.searchModel = new SearchModel();
    }

    @Override
    public void getSearchList(String search,int page) {
        iSearchView = getView();
        RxObserver<SearchResp> rxObserver = new RxObserver<SearchResp>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iSearchView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(SearchResp searchUserResps) {
               iSearchView.showSearch(searchUserResps);
            }
        };
        searchModel.searchUser(search,page,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getCommenList(int type,int page_no) {
       iSearchView = getView();
       RxObserver<SearchResp> rxObserver = new RxObserver<SearchResp>(this) {
           @Override
           protected void onFaile(int errorCode, String errorMsg) {
           }

           @Override
           protected void onSuccess(SearchResp searchUserResps) {
               iSearchView.showCommenList(searchUserResps);
           }
       };
       searchModel.getInitUser(type,page_no,rxObserver);
    }
    /**
     * 关注某人
     *
     * @param follow_id
     */
    @Override
    public void loginFollowFans(String follow_id) {
        iSearchView = getView();
        Callback<BaseDataBean<FollowBean>> rxObserver = new Callback<BaseDataBean<FollowBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
                iSearchView.getFollowResult(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {

            }


        };

        searchModel.getFollowNotification(follow_id, rxObserver);
    }

    @Override
    public void loginNoFollow(String follow_id, int position) {
        iSearchView = getView();
        RxObserver<FollowBean> rxObserver = new RxObserver<FollowBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {

            }

            @Override
            protected void onSuccess(FollowBean followBean) {
                iSearchView.showNoFollowResult(followBean, position);
            }
        };

        searchModel.getNoFollowNotification(follow_id, rxObserver);
        addDisposable(rxObserver);
    }
}
